package Q674;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * 最长连续递增序列
 *
 * @author 23737
 * @time 2021.11.27
 */
public class Test {
    public static void main(String[] args) {
        System.out.println(new Solution().findLengthOfLCIS(new int[]{2, 1, 3}));
        System.out.println(new Solution().findLengthOfLCIS(new int[]{1, 2, 3, 4, 5}));
//        System.out.println(new Solution().findLengthOfLCIS(new int[]{2, 2, 2, 2, 2}));
    }
}

/**
 * 滑动窗口
 */
class Solution2 {
    public int findLengthOfLCIS(int[] nums) {
        if (nums.length < 1) {
            return 0;
        }
        int count = 0;
        int max = 1;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] > nums[i - 1]) {
                max = Math.max(max, i - count + 1);
            } else {
                count = i;
            }
        }
        return max;
    }
}

/**
 * list
 */
class Solution {
    public int findLengthOfLCIS(int[] nums) {
        if (nums.length == 1) {
            return 1;
        }
        int count = 1;
        List<Integer> list = new ArrayList<>();
        for (int i = 1; i < nums.length; i++) {
            if (nums[i - 1] < nums[i]) {
                count++;
            } else {
                count = 1;
            }
            list.add(count);
        }
        Collections.sort(list);
        return list.get(list.size() - 1);
    }
}

/**
 * dp
 */
class Solution3 {
    public int findLengthOfLCIS(int[] nums) {
        int[] dp = new int[nums.length];
        Arrays.fill(dp, 1);
//        int res = 1;
        for (int i = 0; i < nums.length - 1; i++) {
            if (nums[i + 1] > nums[i]) {
                dp[i + 1] = dp[i] + 1;
            }
//            res = res > dp[i + 1] ? res : dp[i + 1];
        }
        Arrays.sort(dp);
        return dp[dp.length-1];
    }

}




